<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" width="600px" @close="close">
    <el-form ref="form" label-width="160px" :model="form" :rules="rules">
      <el-form-item v-if="!isAdd" label="关键问题" prop="product.id">
        <el-input v-model.trim="关键问题" autocomplete="off" :disabled="true" />
      </el-form-item>
      <el-form-item label="产品名称" prop="product.name">
        <el-input v-model.trim="form.product.name" autocomplete="off" />
      </el-form-item>
      <el-form-item label="产品名称" prop="文案标题">
        <el-input v-model.trim="文案标题" autocomplete="off" />
      </el-form-item>
      <el-form-item label="二级分类" prop="product.class">
        <el-input v-model.trim="form.product.class" autocomplete="off" />
      </el-form-item>
      <el-form-item label="优先级（数字)" prop="product.priority">
        <el-input v-model.number="form.product.priority" autocomplete="off" />
      </el-form-item>
      <el-form-item label="推荐理由" prop="product.desc">
        <el-input v-model.trim="form.product.desc" autocomplete="off" type="textarea" />
      </el-form-item>
      <el-form-item label="产品图片url" prop="product.url">
        <el-input v-model.trim="form.product.url" autocomplete="off" />
      </el-form-item>
      <!-- <el-form-item label="产品标签"></el-form-item> -->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">保 存</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { doEdit } from '@/api/configration'
  // import { getEditPrizeConfigProps } from '../../utils.js'
  export default {
    name: 'TableEdit',
    data() {
      return {
        isAdd: false,
        form: {
          prizeid: '',
          name: '',
          count: 0,
          text: '',
          countDesc: '',
          continuous: '',
        },
        list: {},
        rules: {
          'product.id': [{ required: true }],
          'product.name': [{ required: true, trigger: 'blur', message: '请输入产品名称' }],
          count: [
            { required: true, trigger: 'blur', message: '请输入打卡天数（数字）' },
            {
              type: 'number',
              message: '请输入打卡天数须为整数数字',
              trigger: 'blur',
            },
          ],
          text: [{ required: true, trigger: 'blur', message: '请输入进度提示词' }],
          countDesc: [{ required: true, trigger: 'blur', message: '请输入弹窗展示词' }],
          continuous: [{ required: true, trigger: 'blur', message: '请选择是否连续' }],
        },
        title: '',
        dialogFormVisible: false,
        defaultContinuous: '',
      }
    },
    created() {},
    methods: {
      showEdit(list, row) {
        console.log('显示', list)
        if (!row) {
          this.title = '添加优惠券权益'
          this.isAdd = true
        } else {
          this.title = '编辑优惠券权益'
          this.form = Object.assign({}, row)
          this.isAdd = false
          // this.defaultContinuous = this.from.continuous
        }
        this.list = list
        this.dialogFormVisible = true
      },
      close() {
        console.log('close----')
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
        this.$emit('fetch-data')
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            this.$forceUpdate()
            console.log(this.form, '....save.........', this.list)
            // const props = getEditPrizeConfigProps(this.form, this.list, this.add)
            // console.log('传递参数---', props, this.$options)
            // const { error, data } = await doEdit(props)

            this.$baseMessage(data, 'success')
            this.close()
          } else {
            return false
          }
        })
      },
    },
  }
</script>
